package cool.taomu.toolkit.entity

import java.util.List
import org.eclipse.xtend.lib.annotations.Accessors
import org.eclipse.xtend.lib.annotations.ToString

@Accessors
@ToString
class DataSourceConfigEntity {
    // 基础信息
    String driverClassName;
    String url;
    List<String> urlList; // 支持多个URL（负载均衡）
    String username;
    String password;
    Boolean defaultAutoCommit = true  // 可为 null，默认 true

    // 连接池大小相关
    int initialSize = 5;
    int minIdle = 5;
    int maxIdle = 20;
    int maxActive = 50;
    long maxWait = 10_000; // 单位：毫秒
    long validationInterval = 30_000;

    // 连接有效性检测
    boolean testWhileIdle = true;
    boolean testOnBorrow = false;
    boolean testOnReturn = false;
    boolean useValidationQuery = true;
    String validationQuery = "SELECT 1"; // 默认验证SQL
    // HikariCP 特有配置
    int maximumPoolSize = 10;
    long connectionTimeout = 30_000; // 单位：毫秒
    long idleTimeout = 600_000; // 单位：毫秒
    long maxLifetime = 1_800_000; // 单位：毫秒
    boolean isReadOnly = false;

    // Druid 特有配置
    boolean useUnfairLockForPooling = true;
    int filters = 1; // 1: stat, 2: wall, 3: stat+wall
    boolean resetStatEnable = true;
    boolean logAbandoned = true;
    String webStatFilterUrlPattern = "/*";
    String statViewServletUrlPattern = "/druid/*";
    boolean resetEnable = true;

    // DBCP2 / C3P0 / Tomcat JDBC Pool 共用属性
    boolean removeAbandoned = true;
    long abandonedTimeout = 300_000; // 单位：毫秒
    boolean enableJmx = true;

    // BoneCP / Vibur DCP 预留字段（可选）
    int partitionCount = 3;
    boolean closeOpenStatements = true;
    long statementReleaseInterval = 30_000; // 单位：毫秒
    // 网络与安全
    String proxyHost;
    int proxyPort;
    boolean sslEnabled = false;
    String sslTrustStorePath;
    String sslTrustStorePassword;

    // 健康检查
    long healthCheckTimeout = 5_000; // 单位：毫秒
    // 初始化SQL脚本
    List<String> connectionInitSqls;

    // 连接池类型
    String poolType = PoolType.HIKARI.name;

    enum PoolType {
        HIKARI,
        DRUID,
        DBCP2,
        C3P0,
        TOMCAT_JDBC,
        VIBUR,
        BONECP
    }

}
